<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8" %>
<%@ include file="/WEB-INF/common/taglibs.jsp"%>

<script type="text/javascript">

	function doSearch(){
		$("#grid_table").gridUtil().searchGrid($("#form_search"));
	}

	function doReset(){
		$("#form_search")[0].reset();
	}

	var searchUrl = "userManager-search.action";
	var editUrl = "userManager-edit.action";
	var deleteUrl = "userManager-delete.action";
	var exportUrl = "userManager-export.action";

	$(document).ready(function(){
		// form toggle
		$(".block_title > .block_show").parent().collapseBlock({collapsed:false});

		$("#grid_table").gridUtil().simpleGrid({
			url: searchUrl,
			rowNum: 30,
			caption: "用户列表",
			pager: "#grid_pager",
			footerrow: true,
			userDataOnFooter: true,
			//multiSort: true,
			sortable:true,
			sortname:'modify_time',
			sortorder:'desc',
			toolbar: [true,"top"],
			gridComplete: function() {
				var ids = $("#grid_table").jqGrid('getDataIDs');
				for(var i=0;i < ids.length;i++){
					// 获取数据ID，提交指定URL
					var mod = "<a href='javascript:void(0)' class='a_btn_edit m-r ' onclick='window.location=\"#editUrl?id=#id\"'><em>修改</em></a>";
					mod = mod.replace(/#editUrl/, editUrl).replace(/#id/, ids[i]);
					
					$("#grid_table").jqGrid('setRowData',ids[i],{operation: mod});
				}
			},
			colModel:[
					{label: '操作', name:'operation',align:'center', width: 80, hidedlg: true},
					{label: '编号', name:'id', index:'id', key:true, width:160, hidden:true, hidedlg: true},
					{label: '登录名', name:'loginCode',index:'login_code', width:120},
					{label: '姓名', name:'name',index:'name', width:90},
					{label: '创建时间', name:'createTime',index:'create_time', width:120, formatter:'date'},
					{label: '修改时间', name:'modifyTime',index:'modify_time', width:120, formatter:'date'},
					{label: '邮箱', name:'email',index:'email', width:125},
					{label: '电话', name:'phone',index:'phone', width:100},
					{label: '地址', name:'address',index:'address', width:120},
					{label: '备注', name:'memo',index:'memo', width:100}
			]
		}, {heightfixed: true, pageCache: true});

		// jqGrid 动态显示列
		$("#grid_table").gridUtil().customizeColumn();

		// jqGrid toolbar
		$("#grid_toolbar").appendTo($("#t_grid_table"));

		// 查询
		$("#button_search").click(doSearch);

		// 重置
		$("#button_reset").click(doReset);

		// 新增
		$("#button_add").click(function(){
			window.location = editUrl;
		});

		// 删除
		$("#button_delete").click(function(){
			var selectIds = $("#grid_table").jqGrid('getGridParam','selarrrow');
			if (selectIds != null && selectIds != "") {
				$.ajax({
					type: "POST",
					url: deleteUrl,
					data: ({ids: selectIds}),
					success: function(result) {
						if(result.success == true) {
							$.growlUI('成功信息！', '删除操作成功！');
							$("#grid_table").trigger("reloadGrid");
						} else {
							$.boxUtil.error(result.message, {title: '错误'}, function(){});
						}
					}
				});
			} else {
				$.boxUtil.warn('请至少选择一项纪录！', {title: '警告'}, function(){});
			}
		});

		// 导出
		$("#button_export").click(function(){
			$("#grid_table").gridUtil().exportExcel({url: exportUrl/*, openWindow: false*/});
		});

		// input enter event
		$("#form_search input").input().trim().enter(doSearch);
		
	});

</script>

<div class="layout">
	<!-- search -->
	<div class="block m-b">
		<div class="block_title">
			<h3>用户查询</h3>
			<p class="block_show"></p>
		</div>
		<div class="block_container">
			<form id="form_search" onsubmit="return false;">
			<table cellpadding="0" cellspacing="0" class="table_form">
				<tbody>
					<tr>
						<th width="90">登录名：</th>
						<td width="15%">
							<input name="condition.loginCode" class="width_b" />
						</td>
						<th width="90">姓名：</th>
						<td width="15%">
							<input name="condition.name" class="width_b" />
						</td>
						<th width="90">创建时间：</th>
						<td width="30%">
						<input name="condition.beginCreateTime" class="Wdate width_date" onfocus="WdatePicker()" />
						到
						<input name="condition.endCreateTime" class="Wdate width_date" onfocus="WdatePicker()" />
						</td>
					</tr>
					<tr>
						<th>邮箱：</th>
						<td><input name="condition.email" class="width_b" /></td>
						<th>电话：</th>
						<td><input name="condition.phone" class="width_b" /></td>
						<th>地址：</th>
						<td><input name="condition.address" class="width_d" /></td>
					</tr>
				</tbody>
			</table>
			</form>
			<div class="btn_right">
				<span class="form_tips">支持回车键查询</span>
				<a id="button_search" class="easyui-linkbutton l-btn" href="javascript:void(0)"><span class="l-btn-left"><span class="l-btn-text icon-find">查询</span></span></a>
				<a id="button_reset" class="easyui-linkbutton l-btn" href="javascript:void(0)"><span class="l-btn-left"><span class="l-btn-text icon-reset">重置</span></span></a>
				<a id="button_export" class="easyui-linkbutton l-btn" href="javascript:void(0)"><span class="l-btn-left"><span class="l-btn-text icon-excel">导出</span></span></a>
			</div>
		</div>
	</div>
	<!-- result -->
	<div class="block m-b">
		<table id="grid_table"></table>
		<div id="grid_pager"></div>
		<div id="grid_toolbar">
			<a id="button_add" class="l-btn-plain l-btn	m-l4" href="javascript:void(0)"><span class="l-btn-left"><span class="l-btn-text icon-add">新增</span></span></a>
			<a id="button_delete" class="l-btn-plain l-btn"	href="javascript:void(0)"><span	class="l-btn-left"><span class="l-btn-text icon-remove">删除</span></span></a>
		</div>
	</div>
</div>
